package com.cheng.demo.async.service;

import lombok.extern.java.Log;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicInteger;

@Log
@Service
public class AsyncTestService {

    @Async
    public void testAsync(int i, CountDownLatch countDownLatch) throws InterruptedException {
        log.info("==========开始异步: {}===========" + i);
        Thread.sleep(3000);
        log.info("==========异步结束: {}===========" + i);
        countDownLatch.countDown();
    }

    public void test(int i, CountDownLatch countDownLatch) throws InterruptedException {
        this.testAsync(i, countDownLatch);
    }
}
